package com.huike.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.huike.pojo.Dispensing;
import com.huike.pojo.Register;
import com.huike.service.DispensingService;
import com.huike.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
@RequestMapping("dispensing")
@ResponseBody
public class DispensingController {
    @Autowired
    private DispensingService dispensingService;
    @RequestMapping("list")
    public ResultVO getRegisterList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5")  Integer pageSize){

        PageHelper.startPage(pageNum,pageSize);
        List<Register> registers = dispensingService.getRegisterList();
        PageInfo pageInfo = new PageInfo(registers,5);

        return new ResultVO(pageInfo);
    }
    @RequestMapping("add")
    public ResultVO addRegister(Register register){

        try{
            dispensingService.addRegister(register);
            return new ResultVO(200,"添加成功");
        }catch (Exception e){
            return new ResultVO(300,"添加失败");
        }

    }
}
